home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Instrumentation SDK / Documentation / Sample Code / SampleTally.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-19  |  1.6 KB  |  72 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    This code illustrates how to create a tally statistic node and 
  3.  *    how to update its values. The resulting tally has one bucket 
  4.  *    for each of the file types present at the root level of the boot
  5.  *    volume. The bucket ID is the file type; the bucket count is the
  6.  *    number of files of that type present.
  7.  */
  8.  
  9. #include "Instrumentation.h"
  10.  
  11. #include <Files.h>
  12.  
  13.  
  14. OSStatus    InitInstrumentation( void);
  15. OSStatus    TallyRootFileTypes( InstTallyClassRef tally);
  16.  
  17. InstTallyClassRef        gFileTypesTally;
  18.  
  19.  
  20. void        main()
  21. {
  22.     if ( noErr == InitInstrumentation())
  23.     {
  24.         TallyRootFileTypes( gFileTypesTally);
  25.     }
  26. }
  27.  
  28.  
  29. OSStatus    InitInstrumentation( void)
  30. /* Create and enable our statistics nodes. The counts are initially zero. */
  31. {
  32. OSStatus        err;
  33.  
  34.     err = InstCreateTallyClass( kInstRootClassRef, "Samples:File Types", 20, 
  35.                                 kInstEnableClassMask, &gFileTypesTally);
  36.     return err;
  37. }
  38.  
  39.  
  40. OSStatus    TallyRootFileTypes( InstTallyClassRef tally)
  41. /* Count up the types of the files at the root level of the current volume. */
  42. {
  43. CInfoPBRec        pb;
  44. WDPBRec            volPB;
  45. OSStatus        err;
  46. Str63            fName;
  47.  
  48.     volPB.ioCompletion = NULL;
  49.     volPB.ioNamePtr = NULL;
  50.  
  51.     if ( noErr == ( err = PBHGetVolSync( &volPB)))
  52.     {
  53.         pb.hFileInfo.ioCompletion = NULL;
  54.         pb.hFileInfo.ioNamePtr = fName;
  55.         pb.hFileInfo.ioVRefNum = volPB.ioWDVRefNum;
  56.         pb.hFileInfo.ioDirID = 0;
  57.  
  58.         for ( pb.hFileInfo.ioFDirIndex=1; noErr == PBGetCatInfoSync( &pb); pb.hFileInfo.ioFDirIndex++)
  59.         {
  60.             if ( pb.hFileInfo.ioFlAttrib & ioDirMask)        // folder
  61.                 InstUpdateTally( tally, (void*) 'ERIK', 1);
  62.             else
  63.                 InstUpdateTally( tally, (void*) pb.hFileInfo.ioFlFndrInfo.fdType, 1);
  64.             pb.hFileInfo.ioDirID = 0;
  65.         }
  66.     }
  67.  
  68.     return err;
  69. }
  70.  
  71.  
  72.